1 #include<iostream>
2 using
namespace std;
3
4 int
r=0,p=0,k=20;
5 float
allsell=0;
6
7 class
bus{
8
9 char
arriva[9],deprt[9],from[9],to[9],pname[99];
10 int
busn,dtym,tseat,fair,s;
11 public
:
12     
void install();
13     
void show();
14     
void book();
15     
void exit();
16
17
18 }b[
8];
19
20 void
bus::install(void)
21 {
22     cout.setf(ios::right,ios::adjustfield);
23     cout.width(
15);
24 cout<<
"Enter Bus No:";
25 cin>>busn;
26     cout.setf(ios::right,ios::adjustfield);
27     cout.width(
15);
28 cout<<
"\nFrom: ";
29 cin>>
from;
30     cout.setf(ios::right,ios::adjustfield);
31     cout.width(
15);
32 cout<<
"\nTo: ";
33 cin>>to;
34     cout.setf(ios::right,ios::adjustfield);
35     cout.width(
15);
36 cout<<
"\nDeparture: ";
37 cin>>dtym;
38     cout.setf(ios::right,ios::adjustfield);
39     cout.width(
15);
40 cout<<
"\nTotal seats: ";
41 cin>>tseat;
42
43 p++;
44 cout<<
"\n";
45 cout<<
"Bus Information Added!!\n";
46 system(
"PAUSE");
47 system(
"CLS");
48
49 }

50
51 void
bus::show(void)
52 {
53     cout<<
"total bus available:"<<endl;
54     
for(int i=0;i<p;i++)
55         { cout.setf(ios::right,ios::adjustfield);
56             cout.width(
15);
57             cout<<
"Bus No: ";
58             cout<<b[i].busn<<endl;
59             cout.setf(ios::right,ios::adjustfield);
60             cout.width(
15);
61             cout<<
"From: ";
62             cout<<b[i].
from<<endl;
63             cout.setf(ios::right,ios::adjustfield);
64             cout.width(
15);
65             cout<<
"To: ";
66             cout<<b[i].to<<endl;
67             cout.setf(ios::right,ios::adjustfield);
68             cout.width(
15);
69             cout<<
"Departure: ";
70             cout<<b[i].dtym<<
" O'clock"<<endl;
71             cout.setf(ios::right,ios::adjustfield);
72             cout.width(
15);
73             cout<<
"Seats: ";
74             cout<<b[i].tseat<<endl<<endl<<endl;
75
76         }
77         system(
"PAUSE");
78         system(
"CLS");
79 }

80
81
82 void
bus::book(void)
83 {

84 int
number;
85 float
fair;
86     cout<<
"Enter Bus No: ";
87     cin>>number;
88     
int n;
89  
for(n=0;n<p;n++)
90  {
91      
if(b[n].busn==number)
92      {
93         
if(b[n].tseat<=0)
94         {
95         cout<<
"\tSORRY!"<<endl<<"\tNo Seat Available\t";
96         }
97         
else
98         {
99          cout<<endl<<
"Total seat available: "<<b[n].tseat;
100          cout<<endl<<
"Enter Passenger's Name: ";
101          cin>>pname;
102          cout<<endl<<
"Number of seats: ";
103          cin>>s;
104          
while((b[n].tseat=b[n].tseat-s)<0)
105              {cout<<endl<<
"Limit Exceed...Please re-enter ";
106              b[n].tseat=b[n].tseat+s;
107                 cin>>s;
108             
109         
110          }
111
112         
113 cout<<endl<<
"Your purchase is completed"<<endl;
114 cout.setf(ios::right,ios::adjustfield);
115     cout.width(
30);
116 cout<<
"Bus No: ";
117 cout<<b[n].busn<<endl;
118 cout.setf(ios::right,ios::adjustfield);
119     cout.width(
30);
120 cout<<
"From: ";
121 cout<<b[n].
from<<" to "<<b[n].to<<endl;
122 cout.setf(ios::right,ios::adjustfield);
123     cout.width(
30);
124 cout<<
"Departure: ";
125 cout<<b[n].dtym<<
" O'clock"<<endl;
126 cout.setf(ios::right,ios::adjustfield);
127     cout.width(
30);
128 cout<<
"Total seat: ";
129 cout<<s<<endl;
130 fair=
300*s;
131 fair=fair+(fair*.
7);
132 allsell=allsell+fair;
133 cout.setf(ios::right,ios::adjustfield);
134     cout.width(
30);
135 cout<<
"Total Fair(with 7%vat): ";
136
137 cout.setf(ios::showpoint);
138 cout.precision(
3);
139 cout.setf(ios::
fixed,ios::floatfield);
140 cout.width(
8);
141 cout<<fair<<endl;
142
143 cout.setf(ios::right,ios::adjustfield);
144     cout.width(
30);
145 cout<<
"Thank You"<<endl<<endl;
146
147             }
148      }
149  }
150 system(
"PAUSE");
151 system(
"CLS");
152
153 }

154
155 int
main()
156  {
157     
int w,g=1;
158  
while(g){
159  cout<<
"\n\n\t\t\t\t==================================================="<<endl;
160  cout<<
"\t\t\t\t\t\tBus Ticketing System\n";
161  cout<<
"\t\t\t\t==================================================="<<endl;
162
163  cout<<
"\t\t\t\t\t 1 => Install\n\t\t\t\t\t 2 => List Available Bus\n\t\t\t\t\t 3 => Book Tickets\n\t\t\t\t\t 4 => Exit";
164  cout<<
"\n\n\t\t\t\t\t Enter your choice: ";
165  cin>>w;
166  
switch(w){
167  
case 1:
168     b[p].install();
//fn1353p
169
170  
break;
171  
case 2:
172      b[
0].show();
173  
break;
174  
case 3:
175     b[p].book();
176  
177  
break;
178  
case 4:
179      {
180 g=
0;
181
182 cout<<endl<<
"Total Sales:"<<allsell<<endl<<"******Thank You******"<<endl;
183 cout<<
"Brought To You By code-projects.org";
184 break
;
185      }
186  }
187 }

188 return
0;
189 }


Gõ tìm kiếm nhanh...